class User < ActiveRecord::Base
  attr_accessor :remember_me
  
  EMAIL_MAX_LENGTH = 50
  SCREEN_NAME_MIN_LENGTH = 4
  SCREEN_NAME_MAX_LENGTH = 20
  PASSWORD_MIN_LENGTH = 4
  PASSWORD_MAX_LENGTH = 20

  # Form text box sizes for display in view
  SCREEN_NAME_SIZE = 20
  PASSWORD_SIZE = 10
  EMAIL_SIZE = 30
  
  # validation rules
  validates_presence_of :screen_name, :email, :password 
  validates_uniqueness_of :screen_name, :email
  validates_length_of :email, :maximum => EMAIL_MAX_LENGTH
  validates_length_of :screen_name, 
    :within => SCREEN_NAME_MIN_LENGTH..SCREEN_NAME_MAX_LENGTH
  validates_format_of :screen_name,
    :with => /^[A-Z0-9_]*$/i,
    :message => "must contain only letters, numbers and underscores"
  validates_format_of :email,
    :with => /^[A-Z0-9._%-]+@([A-Z0-9-]+\.)+[A-Z]{2,4}$/i,
    :message => "must be a valid email address"
  validates_length_of :password, 
    :within => PASSWORD_MIN_LENGTH..PASSWORD_MAX_LENGTH
    
  def login!(session)
    session[:user_id] = id
  end
end
